package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class MainActivity2 extends AppCompatActivity implements View.OnClickListener {

    public int count = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        ImageView image1 = findViewById(R.id.imageView3);
        ImageView image2 = findViewById(R.id.imageView4);
        ImageView image3 = findViewById(R.id.imageView5);
        ImageView image4 = findViewById(R.id.imageView6);
        Button button = findViewById(R.id.button2);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra("count", count);
                setResult(1, intent);
                MainActivity2.this.finish();
            }
        });
        image1.setOnClickListener(this);
        image2.setOnClickListener(this);
        image3.setOnClickListener(this);
        image4.setOnClickListener(this);
    }
    @Override
    public void onClick(View v) {
        count++;
        v.setVisibility(View.INVISIBLE);
        Toast.makeText(MainActivity2.this, "摘到" + count +"个桃子", Toast.LENGTH_LONG).show();
    }
}